Imports System.Data.SqlClient

Friend Class DBIndex_Factory
    Inherits DBBase

    Public Function GetAllIndexesForTable( _
                        ByVal lTableID As Long, _
                        ByVal lTableRevID As Long) As ArrayList

        Dim oList As New ArrayList

        Dim sSQL As String = "select"
        sSQL = sSQL & "     a.[ID]"
        sSQL = sSQL & " from"
        sSQL = sSQL & "     tDDIndexes a"
        sSQL = sSQL & " where"
        sSQL = sSQL & "     a.[TableID]=" & ValueToDBValue(lTableID)
        sSQL = sSQL & "     and a.[TableRevID]=" & ValueToDBValue(lTableRevID)
        sSQL = sSQL & " order by"
        sSQL = sSQL & "     a.[ID]"

        Dim oData As DataTable = MyBase.ExecuteReadToDataTable(sSQL)

        For Each oRow As DataRow In oData.Rows
            Dim oIndex As New SQLAutoDocLib.Index(oRow.Item(0))
            oIndex.Load()

            oList.Add(oIndex)
        Next

        oData.Dispose()

        Return oList
    End Function

    Public Function GetIndexByName( _
                        ByVal lTableID As Long, _
                        ByVal sIndex As String) As SQLAutoDocLib.Index

        Dim oIndex As SQLAutoDocLib.Index = Nothing

        Dim sSQL As String = "select"
        sSQL = sSQL & "     [ID]"
        sSQL = sSQL & " from"
        sSQL = sSQL & "     tDDIndexes"
        sSQL = sSQL & " where"
        sSQL = sSQL & "     [TableID]=" & ValueToDBValue(lTableID)
        sSQL = sSQL & "     and [Name]=" & ValueToDBValue(sIndex)

        Dim oValue As Object = MyBase.ExecuteScalar(sSQL)

        If IsNumeric(oValue) Then
            oIndex = New SQLAutoDocLib.Index(CLng(oValue))
            oIndex.Load()
        End If

        Return oIndex
    End Function
End Class
